import urllib.request
import urllib.parse
import requests

url='https://baike.baidu.com/item/'+urllib.parse.quote('猪八戒')
head ={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36'}
req=requests.get(url,headers=head)
html_doc=req.text
with open('猪八戒.txt','w',encoding='utf-8') as f:
    f.write(html_doc)

